/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: stmmac driver Vendor Hooks
 */

#ifdef CONFIG_NETBIOS_STMMAC_SPEC

#if !defined(STMMAC_MAIN_EXT_H) || defined(TRACE_HEADER_MULTI_READ)
#define STMMAC_MAIN_EXT_H
#include <linux/phylink.h>
#include <linux/netdevice.h>
#include "common.h"
#include "stmmac.h"
#include "descs.h"

extern int legacy_flag;
#define stmmac_is_legacy_mode() (likely(legacy_flag != 0))

/* legacy function header */
int stmmac_init_rx_buffers_legacy(struct stmmac_priv *priv, struct dma_desc *p,
					int i, gfp_t flags, u32 queue);
void stmmac_free_rx_buffer_legacy(struct stmmac_priv *priv, u32 queue, int i);
int init_dma_desc_rings_legacy(struct net_device *dev, gfp_t flags,
				void (*stmmac_clear_descriptors)(struct stmmac_priv *priv),
				void (*stmmac_display_rings)(struct stmmac_priv *priv));
void free_dma_rx_desc_resources_legacy(struct stmmac_priv *priv);
int alloc_dma_rx_desc_resources_legacy(struct stmmac_priv *priv);
int stmmac_rx_legacy(struct stmmac_priv *priv, int limit, u32 queue);

/* hook driver header */
/* stmmac main funtion */
void trace_stmmac_fill_rx_buf_sz(struct stmmac_priv *priv, uint i, u32 queue);
int trace_stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
void trace_stmmac_set_bfsize(int mtu, int bufsize, int *result);
int trace_stmmac_phy_init_begin(struct net_device *dev);
void trace_stmmac_phy_init_end(struct stmmac_priv *priv);
int trace_stmmac_open_legacy(struct net_device *dev,
				int (*stmmac_hw_setup)(struct net_device *dev, bool ptp_register),
				void (*free_dma_desc_resources)(struct stmmac_priv *priv),
				irqreturn_t (*stmmac_interrupt)(int irq, void *dev_id),
				void (*timer)(struct timer_list *t));
void trace_stmmac_phy_free_res(void);
int trace_stmmac_release_legacy(struct net_device *dev,
							void (*free_res)(struct stmmac_priv *priv));
int trace_stmmac_xmit_do_frags(struct stmmac_priv *priv, int nfrags);
int trace_stmmac_xmit_ring_full(struct stmmac_priv *priv);
void trace_stmmac_xmit_jumbo(struct stmmac_priv *priv, int entry);
void trace_stmmac_fix_features(netdev_features_t *features);
void trace_stmmac_deal_flowctl(struct stmmac_priv *priv, int status);
int trace_stmmac_set_mac_address(struct net_device *ndev, void *p);
void trace_stmmac_dvr_probe_before(struct device *device,
							int *debug, int *flowctl);
int trace_stmmac_dvr_probe(struct stmmac_priv *priv,
					void (*stmmac_init_fs)(struct net_device *dev));
int trace_stmmac_dvr_remove(struct stmmac_priv *priv);
/* dwmac1000 core and dma */
void trace_dwmac1000_dma_init(void __iomem *ioaddr, u32 *value);
void trace_dwmac1000_configure_fc_dgf(u32 *csr6);
void trace_dwmac1000_core_init(int mtu, void __iomem *ioaddr);
void trace_dwmac1000_set_filter_legacy(struct mac_device_info *hw,
					struct net_device *dev);
/* hwif */
void trace_stmmac_dwmac1_quirks(struct stmmac_priv *priv);
/* platform setup */
void trace_stmmac_probe_config_dt(struct plat_stmmacenet_data *plat,
					struct stmmac_dma_cfg *dma_cfg, struct device_node *np);
/* rx legacy */
int trace_enh_desc_get_rx_owner(struct dma_desc *p);
void trace_flowctrl_pump(struct sk_buff *skb);
void trace_napi_receive(struct stmmac_channel *ch, struct sk_buff *skb);
/* ring mode */
void trace_stmmac_refill_desc3(struct stmmac_priv *priv, struct dma_desc *p);
void trace_stmmac_init_desc3(struct dma_desc *p);
void trace_set_16kib_bfsize(int mtu, int *ret);
/* ethtool */
void trace_stmmac_get_ethtool_stats(u64 *data, int index);
void trace_stmmac_get_sset_count(int *len);
void trace_stmmac_stats_get_strings(struct stmmac_priv *priv, u8 *data);
int trace_stmmac_ethtool_get_link_ksettings(struct net_device *dev,
					    struct ethtool_link_ksettings *cmd);
int trace_stmmac_ethtool_set_link_ksettings(struct net_device *dev,
					    const struct ethtool_link_ksettings *cmd);
#endif

#else /* CONFIG_NETBIOS_STMMAC_SPEC */

#include <linux/tracepoint.h>

#define stmmac_is_legacy_mode() (false)

struct stmmac_channel;

/* legacy function */
static inline __maybe_unused
int stmmac_init_rx_buffers_legacy(struct stmmac_priv *priv, struct dma_desc *p,
					int i, gfp_t flags, u32 queue)
{
	return 0;
}

static inline __maybe_unused
void stmmac_free_rx_buffer_legacy(struct stmmac_priv *priv, u32 queue, int i) {}

static inline __maybe_unused
int init_dma_desc_rings_legacy(struct net_device *dev, gfp_t flags,
				void (*stmmac_clear_descriptors)(struct stmmac_priv *priv),
				void (*stmmac_display_rings)(struct stmmac_priv *priv))
{
	return 0;
}

static inline __maybe_unused
void free_dma_rx_desc_resources_legacy(struct stmmac_priv *priv) {}

static inline __maybe_unused
int alloc_dma_rx_desc_resources_legacy(struct stmmac_priv *priv)
{
	return 0;
}

static inline __maybe_unused
int stmmac_rx_legacy(struct stmmac_priv *priv, int limit, u32 queue)
{
	return 0;
}

/* hook driver */
/* stmmac main function */
static inline __maybe_unused
void trace_stmmac_fill_rx_buf_sz(struct stmmac_priv *priv, uint i, u32 queue) {}

static inline __maybe_unused
int trace_stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
	return 0;
}

static inline __maybe_unused
void trace_stmmac_set_bfsize(int mtu, int bufsize, int *result) {}

static inline __maybe_unused
int trace_stmmac_phy_init_begin(struct net_device *dev)
{
	return 0;
}

static inline __maybe_unused
void trace_stmmac_phy_init_end(struct stmmac_priv *priv) {}

static inline __maybe_unused
int trace_stmmac_open_legacy(struct net_device *dev,
				int (*stmmac_hw_setup)(struct net_device *dev, bool ptp_register),
				void (*free_dma_desc_resources)(struct stmmac_priv *priv),
				irqreturn_t (*stmmac_interrupt)(int irq, void *dev_id),
				void (*timer)(struct timer_list *t))
{
	return 0;
}

static inline __maybe_unused
void trace_stmmac_phy_free_res(void) {}

static inline __maybe_unused
int trace_stmmac_release_legacy(struct net_device *dev,
							void (*free_res)(struct stmmac_priv *priv))
{
	return 0;
}

static inline __maybe_unused
int trace_stmmac_xmit_do_frags(struct stmmac_priv *priv, int nfrags)
{
	return 0;
}

static inline __maybe_unused
int trace_stmmac_xmit_ring_full(struct stmmac_priv *priv)
{
	return 0;
}

static inline __maybe_unused
void trace_stmmac_xmit_jumbo(struct stmmac_priv *priv, int entry) {}

static inline __maybe_unused
void trace_stmmac_fix_features(netdev_features_t *features) {}

static inline __maybe_unused
void trace_stmmac_deal_flowctl(struct stmmac_priv *priv, int status) {}

static inline __maybe_unused
int trace_stmmac_set_mac_address(struct net_device *ndev, void *p)
{
	return 0;
}

static inline __maybe_unused
void trace_stmmac_dvr_probe_before(struct device *device,
							int *debug, int *flowctl)
{}

static inline __maybe_unused
int trace_stmmac_dvr_probe(struct stmmac_priv *priv,
					void (*stmmac_init_fs)(struct net_device *dev))
{
	return 0;
}

static inline __maybe_unused
int trace_stmmac_dvr_remove(struct stmmac_priv *priv)
{
	return 0;
}

/* dwmac1000 core and dma */
static inline __maybe_unused
void trace_dwmac1000_dma_init(void __iomem *ioaddr, u32 *value) {}

static inline __maybe_unused
void trace_dwmac1000_configure_fc_dgf(u32 *csr6) {}

static inline __maybe_unused
void trace_dwmac1000_core_init(int mtu, void __iomem *ioaddr) {}

static inline __maybe_unused
void trace_dwmac1000_set_filter_legacy(struct mac_device_info *hw,
											struct net_device *dev)
{}

/* hwif */
static inline __maybe_unused
void trace_stmmac_dwmac1_quirks(struct stmmac_priv *priv) {}

/* platform setup */
static inline __maybe_unused
void trace_stmmac_probe_config_dt(struct plat_stmmacenet_data *plat,
					struct stmmac_dma_cfg *dma_cfg, struct device_node *np)
{}

/* rx legacy */
static inline __maybe_unused
int trace_enh_desc_get_rx_owner(struct dma_desc *p)
{
	return 0;
}

static inline __maybe_unused
void trace_flowctrl_pump(struct sk_buff *skb) {}

static inline __maybe_unused
void trace_napi_receive(struct stmmac_channel *ch, struct sk_buff *skb) {}

/* ring mode */
static inline __maybe_unused
void trace_stmmac_refill_desc3(struct stmmac_priv *priv, struct dma_desc *p) {}

static inline __maybe_unused
void trace_stmmac_init_desc3(struct dma_desc *p) {}

static inline __maybe_unused
void trace_set_16kib_bfsize(int mtu, int *ret) {}

/* ethtool */
static inline __maybe_unused
void trace_stmmac_get_ethtool_stats(u64 *data, int index) {}

static inline __maybe_unused
void trace_stmmac_get_sset_count(int *len) {}

static inline __maybe_unused
void trace_stmmac_stats_get_strings(struct stmmac_priv *priv, u8 *data) {}

static inline __maybe_unused
int trace_stmmac_ethtool_get_link_ksettings(struct net_device *dev,
					    struct ethtool_link_ksettings *cmd)
{
	return 0;
}

static inline __maybe_unused
int trace_stmmac_ethtool_set_link_ksettings(struct net_device *dev,
					    const struct ethtool_link_ksettings *cmd)
{
	return 0;
}
#endif
